--- title: 04c01 Trainer: Flow Neighbor Loss and Diffusion Map Regularization keywords: fastai sidebar: home_sidebar summary: "A copy of FRED, tailored with particular loss functions" description: "A copy of FRED, tailored with particular loss functions" nb_path: "04c01 Flow Neighbor Loss and Diffusion Map Regularization.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
from FRED.embed import ManifoldFlowEmbedder
from FRED.trainers import save_embedding_visualization, visualize_points
title = "Flow Neighbor Loss + Diffusion Map Reg"
MFE = ManifoldFlowEmbedder(
            embedding_dimension=2,
            embedder_shape=[3, 4, 8, 4, 2],
            device=device,
            sigma=0.5,
            flow_strength=0.5,
            smoothness_grid=True,
        )
loss_weights = {
            "reconstruction": 1,
            "diffusion map regularization": 1,
            "kld": 0,
            "smoothness": 0,
            "flow neighbor loss": 1,
        }
visualization_functions = [
    save_embedding_visualization,
    visualize_points
]
FREDtrainer = Trainer(FE = MFE, loss_weights=loss_weights, visualization_functions = visualization_functions, device=device, title = title)
{% endraw %}

Testing on the Circle

{% raw %}
from FRED.datasets import directed_circle
from FRED.data_processing import dataloader_from_ndarray, ManifoldWithVectorField
from torch.utils.data import DataLoader
X, flow, labels = directed_circle(num_nodes=2000)
# build dataset
ds = ManifoldWithVectorField(X, flow, labels, sigma="automatic", dmap_coords_to_use=2, nbhd_strategy="flow neighbors", n_neighbors=10)
dataloader = DataLoader(ds, batch_size=None, shuffle=True)
Set sigma =  0.015123187
{% endraw %} {% raw %}
FREDtrainer.fit(dataloader, n_epochs = 10)
{% endraw %} {% raw %}
FREDtrainer.visualize_loss()
{% endraw %} {% raw %}
FREDtrainer.training_gif(duration=200)
{% endraw %} {% raw %}
# %prun -D fredstats.prof FREDtrainer.fit(dataloader, n_epochs = 10)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/Users/adjourner/Projects/FRED/04c01 Flow Neighbor Loss and Diffusion Map Regularization.ipynb Cell 9 in <cell line: 1>()
----> <a href='vscode-notebook-cell:/Users/adjourner/Projects/FRED/04c01%20Flow%20Neighbor%20Loss%20and%20Diffusion%20Map%20Regularization.ipynb#X10sZmlsZQ%3D%3D?line=0'>1</a> get_ipython().run_line_magic('load_ext', 'snakeviz')
      <a href='vscode-notebook-cell:/Users/adjourner/Projects/FRED/04c01%20Flow%20Neighbor%20Loss%20and%20Diffusion%20Map%20Regularization.ipynb#X10sZmlsZQ%3D%3D?line=1'>2</a> get_ipython().run_line_magic('prun', '-D fredstats.prof FREDtrainer.fit(dataloader, n_epochs = 10)')

File ~/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2305, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2303     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2304 with self.builtin_trap:
-> 2305     result = fn(*args, **kwargs)
   2306 return result

File ~/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/core/magics/extension.py:33, in ExtensionMagics.load_ext(self, module_str)
     31 if not module_str:
     32     raise UsageError('Missing module name.')
---> 33 res = self.shell.extension_manager.load_extension(module_str)
     35 if res == 'already loaded':
     36     print("The %s extension is already loaded. To reload it, use:" % module_str)

File ~/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/core/extensions.py:76, in ExtensionManager.load_extension(self, module_str)
     69 """Load an IPython extension by its module name.
     70 
     71 Returns the string "already loaded" if the extension is already loaded,
     72 "no load function" if the module doesn't have a load_ipython_extension
     73 function, or None if it succeeded.
     74 """
     75 try:
---> 76     return self._load_extension(module_str)
     77 except ModuleNotFoundError:
     78     if module_str in BUILTINS_EXTS:

File ~/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/core/extensions.py:92, in ExtensionManager._load_extension(self, module_str)
     90 if module_str not in sys.modules:
     91     with prepended_to_syspath(self.ipython_extension_dir):
---> 92         mod = import_module(module_str)
     93         if mod.__file__.startswith(self.ipython_extension_dir):
     94             print(("Loading extensions from {dir} is deprecated. "
     95                    "We recommend managing extensions like any "
     96                    "other Python packages, in site-packages.").format(
     97                   dir=compress_user(self.ipython_extension_dir)))

File ~/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    125             break
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:984, in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'snakeviz'
{% endraw %}

Testing on the Swiss Roll

{% raw %}
from FRED.embed import ManifoldFlowEmbedder
from FRED.trainers import save_embedding_visualization, visualize_points
title = "Flow Neighbor Loss + Diffusion Map Reg"
MFE = ManifoldFlowEmbedder(
            embedding_dimension=2,
            embedder_shape=[3, 4, 8, 4, 2],
            device=device,
            sigma=0.5,
            flow_strength=0.5,
            smoothness_grid=True,
        )
loss_weights = {
            "reconstruction": 1e-3,
            "diffusion map regularization": 1,
            "flow neighbor loss": 1e-4,
            "smoothness": 0,
            "kld": 0,
            
        }
visualization_functions = [
    save_embedding_visualization,
    visualize_points
]
FREDtrainer = Trainer(FE = MFE, loss_weights=loss_weights, visualization_functions = visualization_functions, device=device, title = title)
{% endraw %} {% raw %}
from FRED.datasets import directed_swiss_roll_delayed
from FRED.data_processing import dataloader_from_ndarray, ManifoldWithVectorField
from torch.utils.data import DataLoader
X, flow, labels = directed_swiss_roll_delayed(num_nodes=2000)
# build dataset
ds = ManifoldWithVectorField(X, flow, labels, sigma=1.1)
dataloader = DataLoader(ds, batch_size=None, shuffle=True)
{% endraw %} {% raw %}
from FRED.datasets import plot_directed_3d
plot_directed_3d(X,flow,labels)
{% endraw %}

Double check that diffusion map makes sense

{% raw %}
DC = dataloader.dataset.diff_coords
plt.scatter(DC[:,0],DC[:,1],c=labels)
<matplotlib.collections.PathCollection>
{% endraw %} {% raw %}
FREDtrainer.fit(dataloader, n_epochs = 10)
{% endraw %} {% raw %}
FREDtrainer.visualize_loss()
{% endraw %} {% raw %}
FREDtrainer.training_gif(duration=200)
{% endraw %}

Double Helix

{% raw %}
from FRED.embed import ManifoldFlowEmbedder
from FRED.trainers import save_embedding_visualization, visualize_points
title = "Flow Neighbor Loss + Diffusion Map Reg"
MFE = ManifoldFlowEmbedder(
            embedding_dimension=2,
            embedder_shape=[3, 4, 8, 4, 2],
            device=device,
            sigma=0.5,
            flow_strength=0.5,
            smoothness_grid=True,
        )
loss_weights = {
            "reconstruction": 0,
            "diffusion map regularization": 1,
            "flow neighbor loss": 1,
            "smoothness": 0.1,
            "kld": 0,
        }
visualization_functions = [
    save_embedding_visualization,
    visualize_points
]
FREDtrainer = Trainer(FE = MFE, loss_weights=loss_weights, visualization_functions = visualization_functions, device=device, title = title)
{% endraw %} {% raw %}
from FRED.datasets import double_helix
from FRED.data_processing import dataloader_from_ndarray, ManifoldWithVectorField
from torch.utils.data import DataLoader
X, flow, labels = double_helix(num_nodes=2000)
# build dataset
ds = ManifoldWithVectorField(X, flow, labels, sigma="automatic", dmap_coords_to_use=3, nbhd_strategy="flow neighbors", n_neighbors=10)
dataloader = DataLoader(ds, batch_size=None, shuffle=True)
Set sigma =  0.08576502
{% endraw %} {% raw %}
from FRED.data_processing import affinity_grid_search
affinity_grid_search(X, flow, sigmas = [0.01,0.05,0.1],flow_strengths=[0,0.1,0.5,1])
{% endraw %} {% raw %}
from FRED.datasets import plot_directed_3d
plot_directed_3d(X, flow, labels)
{% endraw %} {% raw %}
DC = dataloader.dataset.diff_coords
plt.scatter(DC[:,1],DC[:,2],c=labels)
<matplotlib.collections.PathCollection>
{% endraw %} {% raw %}
FREDtrainer.fit(dataloader, n_epochs = 100)
{% endraw %} {% raw %}
FREDtrainer.visualize_loss()
{% endraw %} {% raw %}
FREDtrainer.training_gif(duration=200)
{% endraw %}

Noisy Double Helix

{% raw %}
from FRED.datasets import double_helix, plot_directed_3d
from FRED.data_processing import dataloader_from_ndarray, ManifoldWithVectorField
from torch.utils.data import DataLoader
X, flow, labels = double_helix(num_nodes=2000, noise=0.5)
# build dataset
ds = ManifoldWithVectorField(X, flow, labels, sigma="automatic", dmap_coords_to_use=3, nbhd_strategy="flow neighbors", n_neighbors=10)
dataloader = DataLoader(ds, batch_size=None, shuffle=True)
plot_directed_3d(X, flow, labels)
Set sigma =  0.50821567
{% endraw %}

Ensure that there's enough noise with a PHATE plot

{% raw %}
from phate import phate
phate_op = phate.PHATE()
data_phated = phate_op.fit_transform(X)
phate.plot.scatter2d(phate_op, c=labels)
[autoreload of pandas._config.config failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 345, in update_class
    update_instances(old, new)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 303, in update_instances
    ref.__class__ = new
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/_config/config.py", line 208, in __setattr__
    raise OptionError("You can only set the value of existing options")
pandas._config.config.OptionError: 'You can only set the value of existing options'
]
[autoreload of pandas._libs.tslibs failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 455, in superreload
    module = reload(module)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/_libs/tslibs/__init__.py", line 36, in <module>
    from pandas._libs.tslibs.nattype import (
ImportError: cannot import name 'is_null_datetimelike' from 'pandas._libs.tslibs.nattype' (/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/_libs/tslibs/nattype.cpython-39-darwin.so)
]
[autoreload of pandas.core.dtypes.common failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 455, in superreload
    module = reload(module)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/core/dtypes/common.py", line 69, in <module>
    ensure_float32 = algos.ensure_float32
AttributeError: module 'pandas._libs.algos' has no attribute 'ensure_float32'
]
[autoreload of pandas.core.array_algos.quantile failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 455, in superreload
    module = reload(module)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/core/array_algos/quantile.py", line 15, in <module>
    from pandas.core.nanops import nanpercentile
ImportError: cannot import name 'nanpercentile' from 'pandas.core.nanops' (/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/core/nanops.py)
]
[autoreload of pandas.core.arrays.categorical failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: astype() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.arrays.datetimelike failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: astype() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.base failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: _arith_method() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.arrays.interval failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: astype() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.arrays.numpy_ failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: __neg__() requires a code object with 0 free vars, not 1
]
[autoreload of pandas.core.indexes.category failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: astype() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.numeric failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: _validate_fill_value() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.range failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: sort_values() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.datetimelike failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: _summary() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.datetimes failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: _maybe_cast_slice_bound() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.interval failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: astype() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.indexes.period failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: _maybe_cast_slice_bound() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.core.series failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 455, in superreload
    module = reload(module)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/core/series.py", line 195, in <module>
    class Series(base.IndexOpsMixin, generic.NDFrame):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/core/series.py", line 306, in Series
    base.IndexOpsMixin.hasnans.func, doc=base.IndexOpsMixin.hasnans.__doc__
AttributeError: 'pandas._libs.properties.CachedProperty' object has no attribute 'func'
]
[autoreload of pandas.core.groupby.base failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: __repr__() requires a code object with 2 free vars, not 1
]
[autoreload of pandas.core.groupby.generic failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: describe() requires a code object with 1 free vars, not 0
]
[autoreload of pandas._testing failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 455, in superreload
    module = reload(module)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 613, in _exec
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/pandas/_testing/__init__.py", line 948, in <module>
    cython_table = pd.core.common._cython_table.items()
AttributeError: module 'pandas.core' has no attribute 'common'
]
[autoreload of pandas.io.parsers.c_parser_wrapper failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: __init__() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.io.parsers.python_parser failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 329, in update_class
    if update_generic(old_obj, new_obj):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: __init__() requires a code object with 1 free vars, not 0
]
[autoreload of pandas.io.parsers.readers failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: read_fwf() requires a code object with 5 free vars, not 0
]
Calculating PHATE...
  Running PHATE on 2000 observations and 3 variables.
  Calculating graph and diffusion operator...
    Calculating KNN search...
    Calculated KNN search in 0.01 seconds.
    Calculating affinities...
  Calculated graph and diffusion operator in 0.02 seconds.
  Calculating optimal t...
[autoreload of pandas.io.xml failed: Traceback (most recent call last):
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 257, in check
    superreload(m, reload, self.old_objects)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 480, in superreload
    update_generic(old_obj, new_obj)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 377, in update_generic
    update(a, b)
  File "/Users/adjourner/miniforge3/envs/FRED/lib/python3.9/site-packages/IPython/extensions/autoreload.py", line 289, in update_function
    setattr(old, name, getattr(new, name))
ValueError: read_xml() requires a code object with 5 free vars, not 0
]
    Automatically selected t = 28
  Calculated optimal t in 34.87 seconds.
  Calculating diffusion potential...
  Calculated diffusion potential in 1.25 seconds.
  Calculating metric MDS...
  Calculated metric MDS in 4.23 seconds.
Calculated PHATE in 40.40 seconds.
<AxesSubplot:>
{% endraw %} {% raw %}
idxs = np.random.randint(0,len(X),len(X))
print(idxs)
X = X[idxs]
flow = flow[idxs]
labels = labels[idxs]
ds = ManifoldWithVectorField(X, flow, labels, sigma="automatic", dmap_coords_to_use=10, nbhd_strategy="flow neighbors", n_neighbors=10, )
dataloader = DataLoader(ds, batch_size=None, shuffle=True)
[ 412 1626  175 ...   36  845  748]
Set sigma =  0.4873998
{% endraw %} {% raw %}
from FRED.embed import ManifoldFlowEmbedder
from FRED.trainers import save_embedding_visualization, visualize_points
title = "Flow Neighbor Loss + Diffusion Map Reg"
MFE = ManifoldFlowEmbedder(
    embedding_dimension=2,
    embedder_shape=[3, 4, 8, 4, 2],
    device=device,
    sigma=0.5,
    flow_strength=0.5,
    smoothness_grid=True,
)
loss_weights = {
    "reconstruction": 0,
    "diffusion map regularization": 1,
    "flow neighbor loss": 0,
    "smoothness": 0,
    "kld": 0,
}
visualization_functions = [
    save_embedding_visualization,
    visualize_points
]
FREDtrainer = Trainer(FE = MFE, loss_weights=loss_weights, visualization_functions = visualization_functions, device=device, title = title)
{% endraw %} {% raw %}
FREDtrainer.fit(dataloader, n_epochs=100)
{% endraw %} {% raw %}
FREDtrainer.visualize_embedding()
{% endraw %} {% raw %}
FREDtrainer.training_gif()
{% endraw %}